package com.yunliuchain.examination.common.bean;

import org.springframework.stereotype.Component;


/**
 * 上传文件参数配置
 * @author 朱周城
 * @version 1.0
 * @date 2014年5月29日上午11:39:25
 */
@Component
public class ImageConfig
{
	//700*700
	public static final String LARGE_SUFFIX="_large.jpg";
	public static final int LARGE_WIDTH =790;
	public static final int LARGE_HEIGHT =400;
	//302*302
	public static final String MEDIUM_SUFFIX="_medium.jpg";
	public static final int MEDIUM_WIDTH =345;
	public static final int MEDIUM_HEIGHT=200;
	//170*170
	public static final String THUMBNAIL_SUFFIX="_thumbnail.jpg";
	public static final int THUMBNAIL_WIDTH =173;
	public static final int THUMBNAIL_HEIGHT =173;

	private FileConfig image = new FileConfig(5242880, "gif,jpg,jpeg,png,bmp");
	private FileConfig customerComplaint = new FileConfig(5242880, "gif,jpg,jpeg,png,bmp");
	private FileConfig product = new FileConfig(5242880, "gif,jpg,jpeg,png,bmp");
	private FileConfig adv = new FileConfig(5242880, "gif,jpg,jpeg,png,bmp");
	private FileConfig flash = new FileConfig(5242880, "swf,flv");
	private FileConfig media = new FileConfig(5242880, "swf,flv,mp3,wav,wma,wmv,mid,avi,mpg,asf,rm,rmvb");
	private FileConfig file = new FileConfig(5242880, "gif,jpg,jpeg,png,bmp,doc,docx,pdf,xls,xlsx,ppt,htm,html,txt,zip,rar,gz,bz2");
	
	
	public ImageConfig()
	{
	}
	
	public FileConfig getImage()
	{
		return image;
	}
	public void setImage(FileConfig image)
	{
		this.image = image;
	}
	public FileConfig getFlash()
	{
		return flash;
	}
	public void setFlash(FileConfig flash)
	{
		this.flash = flash;
	}
	public FileConfig getMedia()
	{
		return media;
	}
	public void setMedia(FileConfig media)
	{
		this.media = media;
	}
	public FileConfig getFile()
	{
		return file;
	}
	public void setFile(FileConfig file)
	{
		this.file = file;
	}

	 public enum FileType{
		image,file,flash,media, product,adv,customerComplaint
	}
	
	 public boolean checkFileType(String type){
		FileType[] types = FileType.values();
		for (FileType fileType : types) {
			if (fileType.equals(FileType.valueOf(type))) {
				return true;
			}
		}
		return false;
	 }
	
	public FileConfig getFileConfigure(FileType fileType){
		if (FileType.image.equals(fileType))
		{
			return this.image;
		}else if(FileType.customerComplaint.equals(fileType)){
			return this.customerComplaint;
		}else if(FileType.product.equals(fileType)){
			return this.product;
		}else if(FileType.adv.equals(fileType)){
			return this.adv;
		}else if(FileType.file.equals(fileType)){
			return this.file;
		}else if(FileType.flash.equals(fileType)){
			return this.flash;
		}else if(FileType.media.equals(fileType)){
			return this.media;
		}else{
			throw new RuntimeException("上传目录不存在!");
		}
	}

	@Override
	public String toString() {
		return "ImageConfig [image=" + image + ", product=" + product + ", adv=" + adv + ", flash=" + flash + ", media="
				+ media + ", file=" + file + "]";
	}
	
	
}
